<?php

namespace App\Models;


use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Storage;

class Company extends Base
{
    use SoftDeletes;
    protected $table = 'company';
    protected $appends = ['logo_url'];

    public function getLogoUrlAttribute() {
        if ($this->logo)
            return Storage::disk('upload_company')->url($this->logo);
        else
            return $this->getCompanyDefaultUrl();
    }

    public function type() {
        return $this->belongsTo(Config::class, 'type_id');
    }

    public function position() {
        return $this->hasMany(Position::class, "company_id");
    }

    public function getCompanyDefaultUrl() {
        return env('APP_URL') . '/upload/default/default_company.png';
    }

}
